import path from 'path';

import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import ejs from 'rollup-plugin-ejs';
import uglify from 'rollup-plugin-uglify';




var fileDest = "ohomie";

var plugins = [
    babel({
        exclude: ['src/**/**.html','node_modules/**'],
    }),
    resolve({
        jsnext: true,
        main: true
    }),
    commonjs(),
    json(),
    ejs({
        include: ['**/*.ejs', '**/*.html']
    })
];

const BUNDLE  = process.env.BUNDLE === 'true';

if(BUNDLE){
    //输出名字添加min
    fileDest = fileDest + ".min"
    //压缩脚本
    plugins.push(uglify());
}


export default {
    input: path.resolve(__dirname, './src/app.js'),
    output: {
        name:"ohomie",
        sourcemap:!BUNDLE,
        file: path.resolve(__dirname, `./dist/js/${fileDest}.js`),
        format: 'umd',
        globals:{
            jquery: 'jQuery',
        },
    },
    plugins,
    external: ['jquery'],
    watch: {
        exclude: ['node_modules/**']
    }
};